//标识gis选项卡的计时器
var iCount;
//标识详情选项卡的计时器
var jCount;
$(function(){
	/* 日期格式化 */
	Date.prototype.Format = function(fmt) {
        var o = {
            "M+" : this.getMonth() + 1, //月份
            "d+" : this.getDate(), //日
            "h+" : this.getHours(), //小时
            "m+" : this.getMinutes(), //分
            "s+" : this.getSeconds(), //秒
            "q+" : Math.floor((this.getMonth() + 3) / 3), //季度
            "S" : this.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(fmt))
            fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "")
                    .substr(4 - RegExp.$1.length));
        for ( var k in o)
            if (new RegExp("(" + k + ")").test(fmt))
                fmt = fmt.replace(RegExp.$1,
                        (RegExp.$1.length == 1) ? (o[k])
                                : (("00" + o[k])
                                .substr(("" + o[k]).length)));
        return fmt;
    };
    
    LoadInitDetail();
});

function cleanCount(){
	clearInterval(iCount);
	clearInterval(jCount);
}

//详情定时器
function LoadInitDetail(){
	//清楚所有定时器
	cleanCount();
	var time = 0;
	if(time == 0){
		initDetail();
	}
	time = time + 20000;
	if(time > 0){
		jCount = setInterval('initDetail()',time);
	}
}
//加载详情选项卡的数据
function initDetail(){
	loadTrackDetail();
	loadPointData();
}

//导出跟踪点
function exportTrackPoint(){
	$("input[name='taskId']").val($("#taskId").val());
	$("#exportForm").submit();
	$("#imp").css({'display':'block'});
}

//预览跟踪点图片
function getView(id){
	var pagePath = $("#pagePath").val();
	var resourcePath = $("#resourcePath").val();
	var url = pagePath + "/cleanTask/cleanPipeLineTrack/getViewImg.json";
	//任务Id
	var taskId = $("#taskId").val();
	//追踪点Id
	var pointId = id;
	if("" == taskId || "" == pointId){
		alert("没有获取有效数据，请刷新页面重试");
		return;
	}else{
		$().invoke(url,{"taskId":taskId,"pointId":pointId},[function(m,r){
		    $(".right-extra").children().html("");
		    var html ="";
			var imgList = r.imgList;
			var oneImg = r.oneImg;
			if(null != oneImg && undefined != oneImg){
				html += "<div id='preview' class='spec-preview' >" +
				"<span class='jqzoom'><img  style='width:350px;height: 350px;' jqimg='"+oneImg+"' src='"+oneImg+"' /></span>" +
				"</div>";
				html += "<div class='spec-scroll'> <a class='prev'>&lt;</a> <a class='next'>&gt;</a>" +
				"<div class='items'>" +
				"<ul>";
				if(imgList.length > 0){
					$.each(imgList,function(i,evalue){
						html += "<li><img alt='' bimg='' src='"+evalue.path+"' onmousemove='preview(this);'></li>" ;
					});
				}
				html +="</ul>" +
				"</div>" +
				"</div>";
			}else{
				html += "<div class='no-data '><img src='"+resourcePath+"/images/pig/no-data.png' alt=''/></div>";
			}
			$(".right-extra").children().html(html);
			$("#viewImg").modal("show");
			$(".right-extra").show();
			pointImgView();
		}]);
	}
}

function convertObj(obj){
    return null==obj || "" == $.trim(obj) ? "" : obj;
}

function convertSubStrObj(obj){
	return null==obj || "" == $.trim(obj) || undefined == obj? "" : obj.substr(0,3);
}

//截取字符串，多余的部分用...代替  
function setString(str, len) {  
    var strlen = 0;  
    var s = "";  
    for (var i = 0; i < str.length; i++) {  
        if (str.charCodeAt(i) > 128) {  
            strlen += 2;  
        } else {  
            strlen++;  
        }  
        s += str.charAt(i);  
        if (strlen >= len) {  
            return s+"...";  
        }  
    }  
    return s;  
}  


function convertObjDate(obj){
    return null==obj || "" == $.trim(obj) ? "" : new Date(obj).Format("yyyy-MM-dd hh:mm:ss");
}

//导入跟踪点记录
function importTrackPoint(){
	var upPath = "/cleanTask/cleanPipeLineTrack/importTrackPoint.json?taskId="+$("#taskId").val();
	var title = "导入跟踪记录";
	var data_={"upUrl":upPath,"title":title};
    openUploadDialog(data_);
}

//图片预览
function pigview(obj){
	var dimg = $("#pigview").children("img");
	dimg.attr("src",$(obj).attr("src"));
	$("#pigview").modal("show");
}

/**
 * 动态加载详情页面数据
 */
function loadTrackDetail(){
	var taskId = $("#taskId").val();
	var resourcePath = $("#resourcePath").val();
	var url = $("#pagePath").val() + "/cleanTask/cleanPipeLineTrack/loadTrackDetail.json";
	$().invoke(url,{"taskId":taskId},[function(m,r){
		var task = r.task;
		var pipeLine = r.pipeLine;
		var segment = r.segment;
		var pig = r.pig;
		var point = r.point;
		var result = r.result;
		var imgList = r.imgList;
		var flag = r.flag;
		var res = r.res;
		//装填顶部数据
		$("#taskName").html(task.name);
		$("#linesName").html(pipeLine.name);
		$("#pigType").html(result.piggingType);
		
		$("#lineName").val(pipeLine.name);
		$("#segmentName").val(segment.inspSegmentName);
		
		var _fvalueRoom = convertObj(pig.fromValRoom);
		var _tvalueRoom = convertObj(pig.toValRoom);
		//装填导航条
		var daohang1 = $(".ss").eq(0).children();
		daohang1.html("");
		var html =  "<li class='start'>" +
				"<i><img src='"+resourcePath+"/images/pig/fa.png' alt=''/></i>" +
				"<span class='s01 c-o' title='"+_fvalueRoom+"'>"+_fvalueRoom.substring(0,10)+"</span>" +
				"<span class='s01-4 c-o'>发球时间:"+convertObj(result.sendBallsTime)+"</span>" +
				"<span class='s02 c-o'>绝对距离："+convertObj(pig.fromMile)+"m</span>";
				if("" != convertObj(result.sendBallsTime)){
					html += "<em class='ren active' style='left:15px;'></em>" ;
				}else{
					html += "<em class='ren'></em>" ;
				}
				html+="</li>";
		$.each(point,function(i,evalue){
			var _regionname = convertObj(evalue.REGIONNAME);
			html += "<li class='zhou w80'></li>" +
				"<li class='sl'>";
			
				html+="<i onclick='getOnePointDetail(\""+evalue.PTPID+"\");'><em class='e01'></em></i>";
			
			html += "<span class='s01-1 c-w' title='"+_regionname+"'>"+_regionname.substring(0,10)+"</span>" +
				"<span class='s01-1-1 c-g'>通过时间:"+convertObj(evalue.PASSTIME)+"</span>" +
				"<span class='s02-2 c-g'>距离:"+convertObj(evalue.MILEAGE)+"m</span>" +
				"<span class='s02-2-1 c-g'>平均速度:"+convertObj(evalue.AVGSPEED)+"m/s</span>" +
				"<input type='hidden' name='index' value='"+i+"'/>" ;
				if(null != evalue.PASSTIME){
					html += "<em class='ren active'></em>";
				}else{
					html += "<em class='ren ' style='left:6px;'></em>";
				}
				html += "</li>";
		});
		html += "<li class='zhou w80'></li>" +
				"<li class='end'>" +
				"<i><img src='"+resourcePath+"/images/pig/shou1.png' alt='' style='margin-top:3px;margin-left:4px'/></i>" +
				"<span class='s01 c-o' title='"+_tvalueRoom+"'>"+_tvalueRoom.substring(0,10)+"</span>" +
				"<span class='s01-4 c-o'>收球时间:"+convertObj(result.backBallsTime)+"</span>" +
				"<span class='s02 c-o'>绝对距离："+convertObj(pig.toMile)+"m</span>" ;
			if("" != convertObj(result.backBallsTime)){
				html += "<em class='ren active'></em>" ;
			}else{
				html += "<em class='ren'></em>" ;
			}
			html += "</li>";
		daohang1.html(html);
		swiperWidth($("#aa .sl").length+2);
		
		//装填发球点详情
		$("#fromValRoom").html(pig.fromValRoom);
		$("#fromMile").html(pig.fromMile);
		$("#fromreference").html(pig.fromreference);
		$("#fromreferencedistance").html(pig.fromreferencedistance);
		$("#sendBallsTime").html(result.sendBallsTime);
		$("#sendRecrder").html(result.sendRecrder);
		$("#sendBallsPressureFrom").html(result.sendBallsPressureFrom);
		$("#sendBallsPressureTo").html(result.sendBallsPressureTo);
		$("#sendBallsFlow").html(result.sendBallsFlow);
		$("#interDiameter").html(result.interDiameter);
		$("#piggingType").html(result.piggingType);
		$("#cleanTool").html((null == result.pigType || "" == result.pigType) ? result.detectorType : result.pigType );
		$("#sendPressure").html(result.sendPressure);
		$("#sendInterference").html(result.sendInterference);
		//发球照片
		$("#sendBallImage").html("");
		var sendImghtml = "";
		$.each(imgList,function(i,evalue){
			if(evalue.MARK == 'fa'){
				sendImghtml += "<div class='swiper-slide'><img onclick='pigview(this);' style='width:40px;height: 40px;' src='"+evalue.PATH+"'></div>";
			}
		});
		$("#sendBallImage").html(sendImghtml);
		$("#sendRemark").val(result.sendRemark);
		
		//装填收球点详情
		$("#toValRoom").html(pig.toValRoom);
		$("#toMile").html(pig.toMile);
		$("#toreference").html(pig.toreference);
		$("#fromreferencedistance").html(pig.fromreferencedistance);
		$("#backBallsTime").html(result.backBallsTime);
		$("#recrder").html(result.recrder);
		$("#theBallsPressureFrom").html(result.theBallsPressureFrom);
		$("#theBallsPressureTo").html(result.theBallsPressureTo);
		$("#theBallsFlow").html(result.theBallsFlow);
		$("#avgRate").html(result.avgRate);
		$("#maxPushPressure").html(result.maxPushPressure);
		$("#sewage").html(result.sewage);
		$("#dirt").html(result.dirt);
		//收球照片
		$("#ballbackImage").html("");
		var backImghtml ="";
		$.each(imgList,function(i,evalue){
			if(evalue.MARK == 'shou'){
				backImghtml+= "<div class='swiper-slide'><img onclick='pigview(this);' style='width:40px;height: 40px;' src='"+evalue.PATH+"'></div>";
			}
		});
		$("#ballbackImage").html(backImghtml);
		
		$("#backRemark").val(result.backRemark);
		$("#ventGasVolume").html(result.ventGasVolume);
		$("#actualPassGasVolume").html(result.actualPassGasVolume);
		$("#gasRelativedEnsity").html(result.gasRelativedEnsity);
		$("#avgTempreture").html(result.avgTempreture);
		$("#pigRunLength").html(result.pigRunLength);
		$("#compressionCoefficient").html(result.compressionCoefficient);
		$("#reRecrder").html(result.recrder);
		$("#recordtime").html(result.recordtime);
		$("#pigginGefficiency").html(result.pigginGefficiency);
		if(flag){
			$(".qg-btn").html();
		}else{
			$(".qg-btn").html("<a href='javascript:void(0);' data-toggle='modal' class='btn btn-w140 btn-out-icon btn-h30' style='float:left' onclick='exportTrackPoint();'><em></em>导出跟踪点</a>" +
					"<a href='javascript:void(0);' id='imp' class='btn btn-w140 btn-gzd-icon btn-h30' style='float:left;margin-left:20px;display:none' onclick='importTrackPoint();'><em></em>导入跟踪记录</a>");
		}
		
		//设置title
		var titleObj = $(".qg-info").find("li");
        for(var i=0;i< titleObj.length;i++){
        	var tohtml = titleObj.eq(i).children().eq(1);
        	var titleVal = tohtml.html();
        	if("" != titleVal && null != titleVal && 'undefined' != titleVal){
        		tohtml.attr('title',titleVal.trim());
        	}
        }
        var param=new Object();
        param.ballBackBoolean=0;//没有收球
		var ballBackBoolean = 0; 
		ballBackBoolean=param.ballBackBoolean;
        if(task.staus == "4"){
        	ballBackBoolean = 1;//已收球并完成任务
        }
        var pd = $(".ss").eq(0).children().find(".sl");
		anchorPoint(pd,ballBackBoolean,convertObj(result.sendBallsTime));
        // 如果收球给出弹窗 res存在就表示已经收球(因为res是后台通过收球时间不为空来获取的)
		if(task.staus == "4"){
			if(null != res && undefined != res && res.length > 0){
				var wushui = convertObj(res[0].SEWAGE) == "" ? 0 : convertObj(res[0].SEWAGE);
				var wuwu = convertObj(res[0].DIRT) == "" ? 0 : convertObj(res[0].DIRT);
				var resMsg = "任务名称："+convertObj(res[0].TASKNAME)+"已完成，"+"清管器运行时间："+convertObj(res[0].PIGRUNTIME)+",污水："+wushui+"KG,污物："+wuwu+"KG";
				//此方法在tan0Dialog.jsp中
				tan0Dialog(resMsg);
				cleanCount();
			}
		}
	}]);
}

function loadPointData(){
	var taskId = $("#taskId").val();
	var pagePath = $("#pagePath").val();
	$("#pointData").initTable({
		url:pagePath+"/cleanTask/cleanPipeLineTrack/loadPointData.json?taskId="+taskId,
		columnData:[
		            {title:"跟踪点名称",name:"REGIONNAME",width:"10%",align:"center"},
		            {title:"绝对距离(m)",name:"MILEAGE",width:"10%",align:"center"},
		            {title:"参考点",name:"REFERENCE",width:"10%",align:"center"},
		            {title:"相对参考点距离(m)",name:"DISTANCE",width:"10%",align:"center"},
		            {title:"通过时间",name:"PASSTIME",width:"10%",align:"center"},
		            {title:"记录人",name:"RECRDER",width:"10%",align:"center"},
		            {title:"备注",name:"REMARK",width:"15%",align:"center"},
		            {title:"照片",name:"",width:"5%",align:"center",format:function(json){return getOpt(json.ID)}},
		            ],
		            
        selectDataNow:true,
        onlyFirstPage:true
	});
}


function getOpt(id){
	var html ="<a href='javascript:void;' onclick='getView(\""+id+"\");' class='look_00'></a>";
	return html;
}

function getOnePointDetail(pointId){
	var pagePath = $("#pagePath").val();
	var resourcePath = $("#resourcePath").val();
	var taskId = $("#taskId").val();
	var url = pagePath + "/cleanTask/cleanPipeLineTrack/getPointDetailByPointCode.json";
	var pointCode = $(this).find("span").eq(0).html();
	var html = "";
	$("#pointDetailDiv").html("");
	$().invoke(url,{"pointId":pointId,"taskId":taskId},[function(m,r){
		var d = r.pointDetail;
		var img = r.img;
		html += "<div class='info-conts genzongdian ' style='margin:30px auto'>" +
				"<p class='p-top'><span>跟踪点详情</span></p>" +
				"<div class='fc clearFix'>" +
				"<ul class='u-info'>";
		if(null != d && undefined != d){
			var mil = d.MILEAGE;
			var dis = d.DISTANCE;
			var pt = d.PASSTIME;
			if(null == mil || "" == mil){
				mil = 0;
			}else{
				mil = d.MILEAGE.toFixed(3);
			}
			if(null == dis || "" == dis){
				dis = 0;
			}else{
				dis = d.DISTANCE.toFixed(3);
			}
			if(null == pt || "" == pt){
				pt ="";
			}else{
				pt = d.PASSTIME;
			}
			html += "<li><span class='s1'>跟踪点</span> <span class='s2'>"+convertObj(d.REGIONNAME)+"</span>" +
					"<li><span class='s1'>绝对距离(m)</span> <span class='s2'>"+mil+"</span>" +
					"<li><span class='s1'>最近参考点</span> <span class='s2'>"+convertObj(d.REFERENCE)+"</span>" +
					"<li class='no-r'><span class='s1'>最近参考点距离(m)</span> <span class='s2'>"+dis+"</span>" +
					"<li><span class='s1'>通过时间</span> <span class='s2'>"+pt+"</span>" +
					"<li><span class='s1'>记录人</span> <span class='s2'>"+convertObj(d.RECORDER)+"</span>" +
				"</ul>";
			html += "<div class='img-lb'>" +
					"<span class='title'>照片</span>" +
					"<div class='lb'>" +
					"<div class='swiper-container runner'>" +
					"<div class='swiper-wrapper'>";
					for (var i in img) {
						var imgPath = img[i].PATH;
						if(null == imgPath != "" == imgPath){
							imgPath = "";
						}
						html += "<div class='swiper-slide'><img onclick='pigview(this);' style='width:40px;height:40px;' src='"+img[i].PATH+"'></div>";
					}
			html += "</div>" +
					"<div class='pagin'></div>" +
					"<a href='javascript:void(0);' class='prev'></a>" +
					"<a href='javascript:void(0);' class='next'></a>" +
					"</div>" +
					"</div>" +
					"</div>" +
					"<p class='qg-text'><span class='title'>跟踪点描述</span><textarea rows='' cols='' readonly='readonly' placeholder=''>"+convertObj(d.REMARK)+"</textarea></p>" +
					"</div></div>";
		}
		$("#pointDetailDiv").html(html);
		var titleObj = $(".u-info").find("li");
        for(var i=0;i< titleObj.length;i++){
        	var tohtml = titleObj.eq(i).children().eq(1);
        	var titleVal = tohtml.html();
        	tohtml.attr('title',titleVal);
        }
	}]);
	
    $('.faqiudian').addClass('none')
    $('.genzongdian').removeClass('none');
    $('.shouqiudian').addClass('none');
}

//gis
function loadGisDetail(){
	//清楚所有定时器
	cleanCount();
	var time = 0;
	if(time == 0){
		showAllPointOnMap('init');
	}
	time = time + 20000;
	iCount = setInterval('showAllPointOnMap()',time);
}

function showAllPointOnMap(type){
	var taskId = $("#taskId").val();
	var pagePath = $("#pagePath").val();
	var resourcePath = $("#resourcePath").val();
	var gisResourcePath = $("#gisResourcePath").val();
	var gisArr = new Array();
	var dataArr = new Array();
	var jsonObj = {};
	var url = pagePath +"/cleanTask/cleanPipeLineTrack/initMapData.json";
	$().invoke(url,{"taskId":taskId},[function(m,r){
		var list = r.list;
		var mp = r.map.pig;
		var res = r.map.res;
		var data2 = r.data2;
		var task = r.task;
		
		var _fvalueRoom = convertObj(mp.fromValRoom);
		var _tvalueRoom = convertObj(mp.toValRoom);
		//隐藏域数据
		$("#frompiginfo").val(mp.frompiginfo);
		$("#topiginfo").val(mp.topiginfo);
		var daohang2 = $(".ss").eq(1).children();
		daohang2.html("");
		var html ="<li class='start'>" +
				"<i><img src='"+resourcePath+"/images/pig/fa.png' alt=''></i>" +
				"<span class='s01 c-o' title='"+_fvalueRoom+"'>"+_fvalueRoom.substring(0,10)+"</span>" +
				"<span class='s01-4 c-o'>发球时间:"+convertObj(mp.begTime)+"</span>" +
				"<span class='s02 c-o'>距离:"+convertObj(mp.fromMile)+"m</span>" +
				"<em class='ren'></em>" +
				"</li>";
		$.each(list,function(i,evalue){
			var lng = convertObj(evalue.lng);
			var lat = convertObj(evalue.lat);
			var code = convertObj(evalue.code);
			var _type = convertObj(evalue.type);
			var reference = convertObj(evalue.reference);
			var remark = convertObj(evalue.remark);
			var lineName = convertObj(evalue.lineName);
			var segmentName = convertObj(evalue.segmentName);
			var regionName = convertObj(evalue.regionName);
			var recorder = convertObj(evalue.recorder);
			var passTime = convertObj(evalue.passTime);
			var customnumber = convertObj(evalue.customnumber);
			var recorder = convertObj(evalue.recorder);
			var state = evalue.state;
			var gisId = evalue.gisId;
			var gisStr = gisId + ";";
			var zuobiao = evalue.zuobiao;
			jsonObj = {
					"lng" : lng,
					"lat" : lat,
					"customnumber" : customnumber,
					"code" : code,
					"type" : _type,
					"reference" : reference,
					"remark" : remark,
					"lineName" : lineName,
					"segmentName" : segmentName,
					"regionName" : regionName,
					"recorder":recorder,
					"recorderTime":passTime,
					"state" : state
				};
			dataArr.push(jsonObj);
			var mil = 0;
			if(null != evalue.mileage && undefined != evalue.mileage){
				mil = evalue.mileage.substring(0,convertObj(evalue.mileage).indexOf(".")+4)
			}
			var _regionName = convertObj(evalue.regionName);
			html += "<li class='zhou w80'></li>" +
					"<li class='sl'>" +
					"<i onclick='showPointOnMap("+lng+","+lat+");'><em class='e01'></em></i>" +
					"<span class='s01-1 c-w' title='"+_regionName+"'>"+_regionName.substring(0,10)+"</span>" +
					"<span class='s01-1-1 c-g'>通过时间:"+convertObj(evalue.passTime)+"</span>" +
					"<span class='s02-2 c-g'>距离:"+mil+" m</span>" +
					"<span class='s02-2-1 c-g'>平均速度:"+convertObj(evalue.avgSpeed)+"m/s</span>" +
					"<input type='hidden' name='index' value='"+i+"'/>" ;
			if(convertObj(passTime) != ""){
				html += "<em class='ren active'></em>";
				gisArr.push(jsonObj);
			}else{
				html += "<em class='ren ' style='left:6px;'></em>";
			}
			html +="</li>";
		});
		html += "<li class='zhou w80'></li>" +
				"<li class='start'>" +
				"<i><img src='"+resourcePath+"/images/pig/shou.png' alt='' style='margin-top:4px;margin-left:4px'/></i>" +
				"<span class='s01 c-o' title='"+_tvalueRoom+"'>"+_tvalueRoom.substring(0,10)+"</span>" +
				"<span class='s01-4 c-o'>收球时间:"+convertObj(mp.endTime)+"</span>" +
				"<span class='s02 c-o'>距离:"+convertObj(mp.toMile)+"m</span>" +
				"<em class=''></em> " +
				"</li>";
		daohang2.html(html);
		swiperWidth($("#bb .sl").length+2);
		//收发球桶相关信息
		var param=new Object();
		param.ballBackBoolean=0;//没有收球
		var ballBackBoolean = 0; 
		loadPiggingInfo(dataArr,gisArr,type,mp,param);
		ballBackBoolean=param.ballBackBoolean;
		
		if('init' == type){
			getForm(gisResourcePath + "/bMapTrackRealtime.jsp",dataArr,data2);
		}else{
			document.getElementById("frameId").contentWindow.cleanPipeRealtime(gisArr);
		}
		//调整最新通过的跟踪点在视野内。通过对整个跟踪条html中通过的跟踪点和未通过的跟踪点的样式进行判断
		//1 获取最新通过的点的位置
		var pd = $(".ss").eq(1).children().find(".sl");
		anchorPoint(pd,ballBackBoolean,convertObj(mp.begTime));
		//如果收球 并完成任务 弹出弹出框，结束监控
		if(task.staus == "4"){
			if(null != res && undefined != res && res.length > 0){
				var wushui = convertObj(res[0].SEWAGE) == "" ? 0 : convertObj(res[0].SEWAGE);
				var wuwu = convertObj(res[0].DIRT) == "" ? 0 : convertObj(res[0].DIRT);
				var resMsg = "任务名称："+convertObj(res[0].TASKNAME)+"已完成，"+"清管器运行时间："+convertObj(res[0].PIGRUNTIME)+",污水："+wushui+"KG,污物："+wuwu+"KG";
				//此方法在tan0Dialog.jsp中
				tan0Dialog(resMsg);
				cleanCount();
			}
		}
		
	}]);
}

//导航定位计算完成度
function anchorPoint(obj,ballBackBoolean,sendBallTime){
	var li = obj;
	var em = obj.children("em");
	var count = 0;
	var indexArr = new Array();
	//清管进度
	var progress = 0 + "%";
	for (var i = 0; i < em.length; i++) {
		if(em.eq(i).hasClass("active")){
			count = count + i;
			indexArr.push(Number(obj.eq(i).find("input[name='index']").val()));
		}
	}
	//取出最大index
	var maxIndex;
	if(indexArr.length > 0){
		maxIndex= Math.max.apply(null,indexArr);
	}else{
		maxIndex = -1;
	}
	if((count-1) >= 0){
//		$(".swiper").eq(1).scrollLeft((maxIndex + 1) * 150);
		li.parents(".swiper").scrollLeft((maxIndex + 1) * 150);
	}else{
		li.parents(".swiper").scrollLeft(0);
	}
	
	if(ballBackBoolean == 1){
		progress = "100%";
	}else if("" != sendBallTime && maxIndex == -1){
		progress = Math.round(1 * 100 / (em.length +2)) + "%" ;
	}else if("" == sendBallTime && maxIndex == -1){
		progress = "0%";
	}else{
		progress = Math.round((maxIndex+2) * 100 / (em.length +2)) + "%" ;
	}
	$("#progress").html("已完成:"+progress);
}

/**
 * 
 * @param obj1 跟踪点
 * @param obj2 收发球筒
 * @param type 点击gis按钮类型
 * @param mp 数据
 * @param ballBackBoolean 是否已经收球
 */
function loadPiggingInfo(obj1,obj2,type,mp,param){
	var frompiginfo ="";
	var topiginfo="";
	if('init'==type){
		frompiginfo = convertObj($("#frompiginfo").val());
		topiginfo = convertObj($("#topiginfo").val());
	}else{
		frompiginfo = mp.frompiginfo;
		topiginfo = mp.topiginfo;
	}
	var ssClass = $(".ss").eq(1).find(".start");
	
	var frompiginfoArr = frompiginfo.split("#%#");
	ssClass.eq(0).children("i").attr("onclick","showPointOnMap('"+convertObj(frompiginfoArr[0])+"','"+convertObj(frompiginfoArr[1])+"');");
	var sendBallTime = convertObj(frompiginfoArr[17]);
	var sendState = "";
	if("" == sendBallTime){
		ssClass.eq(0).children("em").addClass("ren");
		sendState = "N";
	}else{
		ssClass.eq(0).children("em").addClass("ren active");
		sendState = "Y";
	}
	var fromPigJson = {
			'lineName':convertObj($("#lineName").val()),
			'segmentName':convertObj($("#segmentName").val()),
			//发球筒X坐标
			'lng' : convertObj(frompiginfoArr[0]),
			//发球筒Y坐标
			'lat' : convertObj(frompiginfoArr[1]),
			//发球筒编号
			'customnumber': convertObj(frompiginfoArr[16]),
			//发球筒统一编号
			'code' : convertObj(frompiginfoArr[15]),
			//发球筒所属场站阀室
			'regionName' : convertObj(frompiginfoArr[3]),
			//发球筒压力等级
			'press' : convertObj(frompiginfoArr[4]),
			//发球筒的小球桶长度
			'SBlength' : convertObj(frompiginfoArr[5]),
			//发球筒的小球筒直径
			'SBdiameter' : convertObj(frompiginfoArr[6]),
			//发球筒的小球筒壁厚
			'SBthick' : convertObj(frompiginfoArr[7]),
			//发球筒的大球桶长度
			'BBlength' : convertObj(frompiginfoArr[8]),
			//发球筒的大球筒直径
			'BBdiameter' : convertObj(frompiginfoArr[9]),
			//发球筒的大球桶壁厚
			'BBthick' : convertObj(frompiginfoArr[10]),
			//发球筒的生产厂商 
			'factory' : convertObj(frompiginfoArr[2]),
			//发球筒的生产日期
			'factoryTime' : frompiginfoArr[11],
			//发球筒的记录人
			'recorder' : convertObj(frompiginfoArr[18]),
			//发球筒的记录时间
			//'recordTime' : convertObjDate(frompiginfoArr[13]),
			'recorderTime' : sendBallTime,
			//发球筒备注
			'remark':convertObj(frompiginfoArr[14]),
			
			'pointType' : 'fromGisPig',
			'sendBallTime':sendBallTime,
			'state' :sendState
	}
	
	var topiginfoArr = topiginfo.split("#%#");
	ssClass.eq(1).children("i").attr("onclick","showPointOnMap('"+convertObj(topiginfoArr[0])+"','"+convertObj(topiginfoArr[1])+"');");
	var backBallTime = convertObj(topiginfoArr[17]);
	var backState = "";
	if("" == backBallTime){
		ssClass.eq(1).children("em").addClass("ren");
		backState = "N"
	}else{
		ssClass.eq(1).children("em").addClass("ren active");
		backState = "Y"
	}
	
	var toPigJson = {
			'lineName':convertObj($("#lineName").val()),
			'segmentName':convertObj($("#segmentName").val()),
			//收球筒X坐标
			'lng' : convertObj(topiginfoArr[0]),
			//收球筒Y坐标
			'lat' : convertObj(topiginfoArr[1]),
			//收球筒编号
			'customnumber': convertObj(frompiginfoArr[16]),
			//收球筒统一编号
			'code' : convertObj(topiginfoArr[15]),
			//收球筒所属场站阀室
			'regionName' : convertObj(topiginfoArr[3]),
			//收球筒压力等级
			'press' : convertObj(topiginfoArr[4]),
			//收球筒的小球桶长度
			'SBlength' : convertObj(topiginfoArr[5]),
			//收球筒的小球筒直径
			'SBdiameter' : convertObj(topiginfoArr[6]),
			//收球筒的小球筒壁厚
			'SBthick' : convertObj(topiginfoArr[7]),
			//收球筒的大球桶长度
			'BBlength' : convertObj(topiginfoArr[8]),
			//收球筒的大球筒直径
			'BBdiameter' : convertObj(topiginfoArr[9]),
			//收球筒的大球桶壁厚
			'BBthick' : convertObj(topiginfoArr[10]),
			//收球筒的生产厂商 
			'factory' : convertObj(topiginfoArr[2]),
			//收球筒的生产日期
			'factoryTime' : convertObj(topiginfoArr[11]),
			//收球筒的记录人
			'recorder' : convertObj(topiginfoArr[18]),
			//收球筒的记录时间
			//'recordTime' : convertObjDate(topiginfoArr[13]),
			'recorderTime' : backBallTime,
			//收球筒备注
			'remark':convertObj(topiginfoArr[14]),
			
			'pointType' : 'toGisPig',
			'backBallTime':backBallTime,
			'state' :backState
	}
	
	//发球筒：'pointType':fromGisPig  收球筒 'pointType':toGisPig
	obj1.push(fromPigJson);
	obj1.push(toPigJson);
	if("" != sendBallTime){
		obj2.push(fromPigJson);
	}
	if("" != backBallTime){
		obj2.push(toPigJson);
		param.ballBackBoolean = 1;
	}
}


/**
 * 加载地图调用的方法
 * @param url 地图绝对路径
 * @param ap
 */
function getForm(url,ap,data2){
	var formObj = document.createElement("form");
	formObj.setAttribute("method","post");
	formObj.setAttribute("action",url);
	var inputObj = document.createElement("input");
	var inputObj2 = document.createElement("input");
	inputObj.setAttribute("type","hidden");
	inputObj.setAttribute("name","gisIdArr");
	
	inputObj2.setAttribute("type","hidden");
	inputObj2.setAttribute("name","pipeInfo");
	var valueStr = "";
	var valueStr2 = "";
	valueStr = JSON.stringify(ap);
	inputObj.setAttribute("value",valueStr);	
	inputObj2.setAttribute("value",data2);	
	formObj.appendChild(inputObj);
	formObj.appendChild(inputObj2);
	document.getElementById('frameId').contentWindow.document.write(formObj.outerHTML);
	document.getElementById('frameId').contentWindow.document.getElementsByTagName("form")[0].submit();
}

//地图定位
function showPointOnMap(lng,lat){
	document.getElementById("frameId").contentWindow.locationMarker(lng,lat);
}
/**
 * 跳转到历史记录
 */
function closeAndHref(){
	$("#tan0").modal("hide");
	var pagePath = $("#pagePath").val();
	var url =  pagePath + "/cleanTask/cleanPipeLineHistory/getCleanPipeLineHistoryIndex.html";
	//这个方法在公共的jsp中
	activeTopLMenu(url);
	window.location.href=url;
}

